package com.test02;

import java.util.Comparator;
import java.util.TreeSet;

public class Test {
    public static void main(String[] args) {
        TreeSet<Student> list = new TreeSet<>(
                new Comparator<Student>() {
                    @Override
                    public int compare(Student o1, Student o2) {
                        int num1= o1.getAge()-o2.getAge();
                        int num2 = num1 == 0 ? o1.getName().compareTo(o2.getName()) : num1;
                        return num2;
                    }
                }
        );

        list.add(new Student("张一",23));
        list.add(new Student("张二",15));
        list.add(new Student("张三",25));
        list.add(new Student("张四",22));
        list.add(new Student("张五",21));
        list.add(new Student("张六",21));
        for (Student s : list) {
            System.out.println(s);
        }
    }
}
